#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>

static int fd_con = -1;
int set_console(char * dev)
{
        if (fd_con >= 0) close(fd_con);
        fd_con = open(dev, O_RDWR|O_NONBLOCK);
        return 0;
}

int putchar(int c)
{
        if (fd_con >= 0) {
                write(fd_con, &c, 1);
        }
        return 0;
}

int getche(void)
{
        int inchar = 0;
        if (fd_con >= 0) {
                while (!read(fd_con, &inchar, 1)){
                }
        }
        return inchar;
}
